package com.huaxin.device.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huaxin.device.dto.ResponseResult;
import com.huaxin.device.dto.request.AlarmThresholdRuleCreateReqDTO;
import com.huaxin.device.dto.request.AlarmThresholdRulePageListReqDTO;
import com.huaxin.device.dto.request.AlarmThresholdRuleUpdateReqDTO;
import com.huaxin.device.models.AlarmThresholdRule;
import com.huaxin.device.service.AlarmThresholdRuleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "报警阈值规则")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/device/alarmThresholdRule")
public class AlarmThresholdRuleController {
    private final AlarmThresholdRuleService service;

    @Operation(summary = "创建报警阈值规则", description = "创建报警阈值规则")
    @PostMapping("/create")
    public ResponseResult<AlarmThresholdRule> create(@RequestBody @Valid AlarmThresholdRuleCreateReqDTO in) {
        return service.create(in);
    }

    @Operation(summary = "获取报警阈值规则", description = "获取报警阈值规则")
    @GetMapping("/get")
    public ResponseResult<AlarmThresholdRule> get(
            @Parameter(description = "规则ID", example = "m_order_001")
            @RequestParam(value = "id", required = true) String id) {
        return ResponseResult.ok(service.getByRuleId(id));
    }

    @Operation(summary = "更新报警阈值规则", description = "更新报警阈值规则")
    @PostMapping("/update")
    public ResponseResult<String> update(@RequestBody @Valid AlarmThresholdRuleUpdateReqDTO in) {
        return service.update(in);
    }

    @Operation(summary = "删除报警阈值规则", description = "删除报警阈值规则")
    @DeleteMapping("/{id}/delete")
    public ResponseResult<String> delete(
            @Parameter(description = "规则ID", example = "m_order_001")
            @PathVariable String id) {
        return service.delete(id);
    }

    @Operation(summary = "启用报警阈值规则", description = "启用报警阈值规则")
    @GetMapping("/enable")
    public ResponseResult<String> enable(
            @Parameter(description = "规则ID", example = "m_order_001")
            @RequestParam(value = "id", required = true) String id) {
        return service.enable(id);
    }

    @Operation(summary = "禁用报警阈值规则", description = "禁用报警阈值规则")
    @GetMapping("/disable")
    public ResponseResult<String> disable(
            @Parameter(description = "规则ID", example = "m_order_001")
            @RequestParam(value = "id", required = true) String id) {
        return service.disable(id);
    }

    @Operation(summary = "分页查询报警阈值规则", description = "分页查询报警阈值规则")
    @PostMapping("/page")
    public ResponseResult<IPage<AlarmThresholdRule>> pageQuery(@RequestBody @Valid AlarmThresholdRulePageListReqDTO in) {
        return service.pageQuery(in);
    }
}
